package com.darren.archive.controller;

import com.darren.archive.entity.City;
import com.darren.archive.entity.Province;
import com.darren.archive.service.CityService;
import com.darren.archive.service.ProvinceService;
import com.darren.framework.bean.ResponseBean;
import com.darren.framework.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(value = "省市信息接口", tags = "省市名称信息接口", description = "省市名称信息接口")
@RestController
public class PlaceController extends BaseController {

    @Resource
    private ProvinceService provinceService;

    @Resource
    private CityService cityService;

    /**
     * 查询所有省份信息
     * @return  所有省份信息
     */
    @ApiOperation(value = "查询所有省份", notes = "查询所有省份")
    @GetMapping("/place/provinces")
    public ResponseBean getProvinces() {
        List<Province> provinces = provinceService.getAll();
        return ResponseBean.isOk(provinces);
    }

    /**
     * 根据 id 查询省份信息
     * @param id  省份id
     * @return    省份信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "省份id", required = true, paramType = "path", dataType = "Long")
    })
    @ApiOperation(value = "根据 id 查询", notes = "根据 id 查询省份信息")
    @GetMapping("/place/province/{id}")
    public ResponseBean getProvince(@PathVariable(name = "id", required = true) Long id) {
        Province province = provinceService.findById(id);
        return ResponseBean.isOk(province);
    }

    /**
     * 根据省份编码查询城市信息
     * @param provinceCode   省份编码
     * @return               城市信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "provinceCode", value = "省份编码", required = true, paramType = "path", dataType = "String")
    })
    @ApiOperation(value = "根据省份编码查询城市", notes = "根据省份编码查询城市信息")
    @GetMapping("/place/province/cities/{provinceCode}")
    public ResponseBean getCities(@PathVariable(name = "provinceCode", required = true) String provinceCode) {
        List<City> cities = cityService.findCitiesByProvinceCode(provinceCode);
        return ResponseBean.isOk(cities);
    }


    /**
     * 查询所有城市信息
     * @return    城市信息
     */
    @ApiOperation(value = "查询所有城市", notes = "查询所有城市信息")
    @GetMapping("/place/cities")
    public ResponseBean getCities() {
        List<City> cities = cityService.getAll();
        return ResponseBean.isOk(cities);
    }

    /**
     * 根据 id 查询城市信息
     * @param id  城市id
     * @return    城市信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "城市id", required = true, paramType = "path", dataType = "Long")
    })
    @ApiOperation(value = "根据 id 查询", notes = "根据 id 查询城市信息")
    @GetMapping("/place/city/{id}")
    public ResponseBean getCity(@PathVariable(name = "id", required = true) Long id) {
        City city = cityService.findById(id);
        return ResponseBean.isOk(city);
    }

}
